#include <stdint.h>

const uint8_t InversePBox[32] =
{
8, 16, 22, 30, 12, 27, 1, 17, 
23, 15, 29, 5, 25, 19, 9, 0, 
7, 13, 24, 2, 3, 28, 10, 18, 
31, 11, 21, 6, 4, 26, 14, 20
};
const uint8_t mapKtoK1[48]=
{
  14, 17, 11, 24,  1,  5,  3, 0,
  15,  6, 21,  10, 23, 19, 12,  4,
  26,  8, 16,  7, 27, 20, 13,  2,
  41, 52, 31, 37, 47, 55, 30, 40,
  51, 45, 33, 48, 44, 49, 39, 28,
  34, 53, 46, 42, 50, 36, 29, 32
};
const uint8_t mapKtoK2[48]=
{
 15, 18, 12, 25,  2,  6,  4, 1,
  16,  7, 22,  11, 24, 20, 13,  5,
  27,  9, 17,  8, 0, 21, 14,  3,
  42, 53, 32, 38, 48, 28, 31, 41,
  52, 46, 34, 49, 45, 50, 40, 29,
  35, 54, 47, 43, 51, 37, 30, 33
};

const uint8_t map_K1toK2[48]=
{
  22, 18, 11, 12,  7,  15,  23, 20,
  0,  5, 21,  100, 100, 100, 2,  6,
  100,  19, 8,  9, 16, 13, 14,  4,
  31, 32, 30, 45, 42, 100, 46, 38,
  44, 36, 47, 28, 100, 35, 100, 29,
  34, 25, 33, 24, 37, 100, 39, 26
};






const uint8_t InverseFinalPermuteMap[64] =
  {
	56, 48, 40, 32, 24, 16, 8, 0, 
	58, 50, 42, 34, 26, 18, 10, 2, 
	60, 52, 44, 36, 28, 20, 12, 4, 
	62, 54, 46, 38, 30, 22, 14, 6, 
	57, 49, 41, 33, 25, 17, 9, 1, 
	59, 51, 43, 35, 27, 19, 11, 3, 
	61, 53, 45, 37, 29, 21, 13, 5, 
	63, 55, 47, 39, 31, 23, 15, 7
};
/*used for InverseKeyCompression*/
const uint8_t InvKeyComp[48] =
  {
  13, 16, 10, 23,  0,  4,  2, 27,
  14,  5, 20,  9, 22, 18, 11,  3,
  25,  7, 15,  6, 26, 19, 12,  1,
  40, 51, 30, 36, 46, 54, 29, 39,
  50, 44, 32, 47, 43, 48, 38, 55,
  33, 52, 45, 41, 49, 35, 28, 31
  };
const uint8_t InverseKeyPermuteMap[56] = 
{
7, 15, 23, 55, 51, 43, 35, 6, 
14, 22, 54, 50, 42, 34, 5, 13, 
21, 53, 49, 41, 33, 4, 12, 20, 
52, 48, 40, 32, 3, 11, 19, 27, 
47, 39, 31, 2, 10, 18, 26, 46, 
38, 30, 1, 9, 17, 25, 45, 37, 
29, 0, 8, 16, 24, 44, 36, 28
};
const uint8_t InversSbox[8][16][4]={

{/*{InvSBox:0}*/
{1, 28, 59, 62},
{6, 15, 34, 45},
{8, 11, 39, 44},
{16, 29, 53, 56},
{2, 7, 32, 41},
{24, 27, 49, 60},
{19, 20, 42, 61},
{5, 30, 47, 54},
{14, 31, 37, 38},
{25, 26, 43, 52},
{17, 18, 57, 58},
{12, 23, 46, 51},
{21, 22, 35, 50},
{4, 13, 40, 63},
{0, 9, 36, 55},
{3, 10, 33, 48}
},

{/*{InvSBox:1}*/
{19, 26, 32, 57},
{2, 21, 39, 46},
{11, 20, 47, 60},
{1, 12, 41, 58},
{5, 14, 42, 45},
{28, 31, 48, 59},
{8, 25, 51, 54},
{7, 18, 36, 53},
{4, 13, 35, 50},
{16, 27, 56, 63},
{23, 30, 37, 40},
{10, 29, 38, 49},
{17, 24, 52, 55},
{3, 22, 33, 44},
{6, 15, 34, 61},
{0, 9, 43, 62}
},

{/*{InvSBox:2}*/
{2, 5, 39, 46},
{16, 31, 33, 50},
{17, 28, 52, 61},
{9, 10, 44, 55},
{11, 26, 36, 49},
{14, 21, 56, 59},
{8, 13, 34, 41},
{3, 22, 47, 62},
{19, 30, 40, 45},
{4, 7, 38, 43},
{0, 15, 35, 58},
{24, 27, 48, 57},
{20, 25, 54, 63},
{1, 18, 32, 37},
{6, 23, 53, 60},
{12, 29, 42, 51}
},

{/*{InvSBox:3}*/
{8, 13, 37, 38},
{16, 25, 43, 50},
{18, 21, 58, 61},
{6, 15, 33, 52},
{17, 28, 51, 62},
{7, 22, 53, 56},
{9, 10, 34, 39},
{0, 19, 44, 59},
{3, 20, 47, 60},
{12, 31, 36, 49},
{14, 27, 32, 41},
{5, 24, 42, 55},
{23, 26, 40, 57},
{1, 2, 45, 46},
{4, 29, 54, 63},
{11, 30, 35, 48}
},

{/*{InvSBox:4}*/
{19, 26, 53, 60},
{6, 15, 36, 41},
{0, 5, 34, 45},
{20, 25, 58, 63},
{4, 9, 32, 59},
{17, 18, 54, 61},
{14, 31, 49, 56},
{8, 11, 39, 44},
{16, 29, 35, 46},
{27, 30, 50, 55},
{10, 23, 40, 57},
{3, 12, 33, 38},
{2, 7, 37, 52},
{13, 24, 42, 47},
{1, 28, 43, 62},
{21, 22, 48, 51}
},

{/*{InvSBox:5}*/
{16, 25, 50, 59},
{2, 19, 53, 56},
{7, 10, 37, 40},
{20, 29, 35, 46},
{5, 22, 33, 52},
{15, 28, 38, 43},
{12, 17, 57, 62},
{9, 26, 48, 55},
{14, 31, 42, 61},
{8, 13, 32, 41},
{1, 4, 47, 54},
{27, 30, 49, 60},
{0, 11, 39, 44},
{18, 21, 58, 63},
{23, 24, 34, 51},
{3, 6, 36, 45}
},

{/*{InvSBox:6}*/
{3, 10, 53, 56},
{13, 30, 32, 41},
{4, 25, 59, 62},
{16, 19, 42, 61},
{0, 9, 34, 43},
{21, 24, 51, 58},
{28, 31, 33, 52},
{7, 22, 44, 47},
{12, 29, 39, 54},
{11, 20, 49, 60},
{15, 26, 45, 48},
{2, 5, 35, 36},
{18, 23, 40, 63},
{1, 14, 37, 38},
{6, 17, 46, 57},
{8, 27, 50, 55}
},

{/*{InvSBox:7}*/
{25, 26, 48, 55},
{1, 14, 35, 38},
{2, 31, 33, 46},
{11, 20, 57, 58},
{6, 15, 36, 41},
{19, 24, 59, 60},
{8, 21, 50, 61},
{13, 30, 32, 39},
{4, 7, 45, 62},
{18, 29, 40, 53},
{9, 16, 43, 52},
{12, 23, 34, 63},
{17, 28, 42, 51},
{0, 5, 47, 54},
{22, 27, 37, 44},
{3, 10, 49, 56}
}
};




